<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="whf.shop.utils.ShopUtils" %>
<%@ page import="java.util.List" %>
<%@ page import="whf.shop.entity.OrderItem" %>
<%@ page import="whf.framework.file.FileUtils" %>
<%@ page import="whf.framework.util.StringUtils" %>
<%@ page import="whf.shop.entity.Product" %>
<%@ page import="whf.framework.util.ParamUtils" %>
<%@ page import="whf.shop.service.ProductServiceImp" %>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%@taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic"%>

<html>
<head>
<script src="<%= request.getContextPath() %>/scripts/alai/alai_menu_xp.js"></script>
<jsp:include page="/common/inc/select.jsp" />
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/pic-view/pic-js/prototype.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/pic-view/pic-js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/pic-view/pic-js/lightbox.js"></script>
<link rel="stylesheet" href="<%= request.getContextPath() %>/scripts/pic-view/pic-css/lightbox.css" type="text/css" media="screen" /> 

<%
List<OrderItem> items = ShopUtils.getCurrentOrder(session).getItems();
pageContext.setAttribute("items", items);

Product detailProduct = null;
long detailProductId = ParamUtils.getLongParameter(request, "detailProductId", 0);
if(detailProductId > 0){
	detailProduct = ProductServiceImp.getProductService().findByPrimaryKey(detailProductId);
	pageContext.setAttribute("detailProduct", detailProduct);
}
%>
<SCRIPT>
function addToCart(pid){
	window.location="<%= request.getContextPath() %>/shop/Order.do?webMethod=addProducts&pid="+pid;
}
</SCRIPT>
</head>
<body>
<table width="100%">
<tr>
	<td width='10%'></td>
	<td width='80%'>
	<logic:present name="detailProduct">
	<table>
		<tr>
			<td colspan='3' align=center><b><framework:attr source="detailProduct" attr="name" /></b>(<framework:attr source="detailProduct" attr="category.name" />)</td>
		</tr>
		<tr>
			<td rowspan='8' valign='top' align='left' width="*%">
			<a name='pic' href="<%= FileUtils.getDownloadFileUrl(request, detailProduct, null) %>" rel="lightbox[plants]">
			<img src='<%= FileUtils.getDownloadFileUrl(request, detailProduct, "large") %>'>
			</a>
			</td>
			<td>说明</td>
			<td><framework:attr source="detailProduct" attr="remarks" /></td>
		</tr>
		<tr>
			<td>单价</td>
			<td><%= ShopUtils.formatPrice(session, detailProduct.getPrice()).getValue() %></td>
		</tr>
		<tr>
			<td>零售价</td>
			<td><%= ShopUtils.formatPrice(session, detailProduct.getRetailPrice()).getValue() %></td>
		</tr>
		<tr>
			<td>折扣</td>
			<td><%= StringUtils.format( (1 - detailProduct.getDiscount()) * 10, "0.0") %></td>
		</tr>
		<tr>
			<td>体积</td>
			<td><framework:attr source="detailProduct" attr="size" /></td>
		</tr>
		<tr>
			<td>重量(KG)</td>
			<td><framework:attr source="detailProduct" attr="weight" /></td>
		</tr>
		<tr>
			<td colspan=2><a href="javascript:addToCart(<framework:attr source="detailProduct" attr="id" />)">添加到购物车</a></td>
		</tr>
	</table>
	</logic:present>
	<logic:notEmpty name="items">
	<form name="form1" method="post" action="<%= request.getContextPath() + "/shop/Order.do" %>">
		<input type='hidden' name='webMethod' value='resetProducts'>
		<framework:table id="<%= String.valueOf(System.currentTimeMillis()) %>" pkStyle="counter" dataSourceName="items" boClassName="whf.shop.entity.OrderItem">
			<framework:column displayTitle="图片">
			<a href="<%= request.getContextPath() %>/shop/Order.do?webMethod=viewMyCart&detailProductId=$product.id">
			<img src='<%= FileUtils.getDownloadFileUrl(request, ((OrderItem)request.getAttribute("currentRow")).getProduct(), "small") %>'>
			</a>
			</framework:column>
			<framework:column displayTitle="产品名称" property="product.name"></framework:column>
			<framework:column displayTitle="产品说明" property="product.remarks"></framework:column>
			<framework:column displayTitle="售价" property="product.price" format="0.00"><%= ShopUtils.formatPrice(session, ((OrderItem)request.getAttribute("currentRow")).getProduct().getPrice()).getValue() %></framework:column>
			<framework:column displayTitle="折扣" property="product.discount" format="0.00"><%= (StringUtils.format( (1-((OrderItem)request.getAttribute("currentRow")).getProduct().getDiscount()) * 10, "0.0")) %></framework:column>
			<framework:column displayTitle="数量" property="quantity"><input type='text' name='q_$product.id' size='5' value='$quantity'><input type='hidden' name='pid' value='$product.id'></framework:column>
			<framework:column displayTitle="总价" property="totalPrice" format="0.00"><%= ShopUtils.formatPrice(session, ((OrderItem)request.getAttribute("currentRow")).getTotalPrice()).getValue() %></framework:column>
		</framework:table>
	</form>
	</logic:notEmpty>
	<logic:present name="deliveries">
	<table width="100%">
		<tr>
			<td width="10%">所有接收人</td>
			<td width="*%"><framework:select name="deliveryId" dataSourceName="deliveries" /></td>
			<td width="10%"></td>
		</tr>
		<tr>
			<td colspan='3'>
			<framework:table view="DELIVERY-MYCART" dataSourceName="currentDelivery" 
				boClassName="whf.shop.entity.Delivery" displayStyle="form" editable="true" />
			</td>
		</tr>
	</table>
	</logic:present>
	<table>
		<tr>
			<td>
			</td>
			<td align='right'>
			<input type='button' value='继续选购' onclick="javascript:window.location='<%= request.getContextPath() %>/shop/index.jsp'">
			<input type='button' value='更新数量' onclick='javascript:form1.submit()'>
			<input type='button' value='下一步' onclick="javascript:window.location='<%= request.getContextPath() %>/shop/Delivery.do?webMethod=selectDeliveries'">
			</td>
		</tr>
	</table>
	</td>
	<td width='10%'></td>
</tr>
</table>
</body>
</html>